import java.util.ArrayList;
import java.util.List;
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 晓星航
 * Date: 2023-11-21
 * Time: 8:39
 */
public class EgyptianScore {
    public static void main(String[] args) {
        int numerator = 7; // 分子
        int denominator = 8; // 分母
        List<String> egyptianFractions = getEgyptianFractions(numerator, denominator);
        System.out.println(numerator + "/" + denominator + " = " + String.join(" + ", egyptianFractions));
    }

    public static List<String> getEgyptianFractions(int numerator, int denominator) {
        List<String> egyptianFractions = new ArrayList<>();

        while (numerator != 0) {
            int ceil = (int) Math.ceil((double) denominator / numerator);
            egyptianFractions.add("1/" + ceil);

            numerator = numerator * ceil - denominator;
            denominator = denominator * ceil;
        }

        return egyptianFractions;
    }
}
